﻿Public Class Resultados
    Dim rs As ADODB.Recordset
    Dim sql As String
    Dim codigo1 As String = ""
    Dim codigoPregunta As String = ""
    Dim nombr As String = ""
    Dim nombrPregunta As String = ""
    Dim pater As String = ""
    Dim paterPregunta As String = ""
    Dim mater As String = ""
    Dim materPregunta As String = ""

    Public Sub New(ByVal Paterno As String, ByVal Materno As String, ByVal nombre As String, ByVal codigo As String)

        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()
        nombr = nombre
        pater = Paterno
        mater = Materno
        codigo1 = codigo

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub
    Private Sub Resultados_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conectar()
        ListaCodigo.Items.Clear()
        Console.WriteLine(codigo1)
        sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE "
        If codigo1.Trim <> "" And pater.Trim <> "" And mater.Trim <> "" And nombr.Trim <> "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (CODI_CLIEN = '" & codigo1 & "') AND (NOMB_CLIEN = '" & nombr & "') AND (PATE_CLIEN = '" & pater & "') AND (MATE_CLIEN = '" & mater & "')"
        ElseIf codigo1.Trim = "" And pater.Trim <> "" And mater.Trim <> "" And nombr.Trim <> "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (CODI_CLIEN = '" & codigo1 & "') AND (NOMB_CLIEN = '" & nombr & "') AND (PATE_CLIEN = '" & pater & "')"
        ElseIf codigo1.Trim = "" And pater.Trim = "" And mater.Trim <> "" And nombr.Trim <> "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (CODI_CLIEN = '" & codigo1 & "') AND (NOMB_CLIEN = '" & nombr & "')"
        ElseIf codigo1.Trim = "" And pater.Trim = "" And mater.Trim = "" And nombr.Trim <> "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (CODI_CLIEN = '" & codigo1 & "')"
        ElseIf codigo1.Trim = "" And pater.Trim <> "" And mater.Trim = "" And nombr.Trim = "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (PATE_CLIEN = '" & pater & "')"
        ElseIf codigo1.Trim = "" And pater.Trim <> "" And mater.Trim <> "" And nombr.Trim = "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (PATE_CLIEN = '" & pater & "') AND (PATE_CLIEN = '" & pater & "')"
        ElseIf codigo1.Trim = "" And pater.Trim = "" And mater.Trim <> "" And nombr.Trim <> "" Then
            sql = "SELECT CODI_CLIEN, NOMB_CLIEN, PATE_CLIEN, MATE_CLIEN FROM CLIENTE WHERE (MATE_CLIEN = '" & mater & "') AND (NOMB_CLIEN = '" & nombr & "')"
        End If
        
        rs = coneccion.Execute(sql)
        While rs.EOF <> True
            If rs.EOF = True Then ''si se convierte en true salir del bucle
                Exit While
            End If
            ListaMate.Items.Add(rs.Fields(3).Value.ToString)
            ListaPate.Items.Add(rs.Fields(2).Value.ToString)
            ListaNom.Items.Add(rs.Fields(1).Value.ToString)
            ListaCodigo.Items.Add(rs.Fields(0).Value.ToString)

            rs.MoveNext()
        End While
    End Sub

    Private Sub Lista_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListaCodigo.MouseDoubleClick
        Resultado = ListaCodigo.SelectedItem.ToString

        Me.Hide()
    End Sub

    Private Sub ListaPate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListaPate.SelectedIndexChanged
        ListaCodigo.SelectedIndex = ListaPate.SelectedIndex
        ListaMate.SelectedIndex = ListaPate.SelectedIndex
        ListaNom.SelectedIndex = ListaPate.SelectedIndex
    End Sub

    Private Sub ListaNom_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListaNom.SelectedIndexChanged
        ListaCodigo.SelectedIndex = ListaNom.SelectedIndex
        ListaMate.SelectedIndex = ListaNom.SelectedIndex
        ListaPate.SelectedIndex = ListaNom.SelectedIndex
    End Sub

    Private Sub ListaMate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListaMate.SelectedIndexChanged
        ListaCodigo.SelectedIndex = ListaMate.SelectedIndex
        ListaNom.SelectedIndex = ListaMate.SelectedIndex
        ListaPate.SelectedIndex = ListaMate.SelectedIndex
    End Sub

    Private Sub Lista_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListaCodigo.SelectedIndexChanged
        ListaNom.SelectedIndex = ListaCodigo.SelectedIndex
        ListaPate.SelectedIndex = ListaCodigo.SelectedIndex
        ListaMate.SelectedIndex = ListaCodigo.SelectedIndex
    End Sub
End Class